<?php
class wordAction extends action {
	
	public function __init(){
	}
	public function init(){
		$this->debug=false;
		$this->display('test/word.html');
		exit;
	}
	
	public function query(){
		$con=sget('q','s','');
		
		if(strlen($con)>2){	//超过2个则区分
			$word=getSearchKeywords($con);
			if(empty($word)){
				$word=$con;	
			}
		}
		$word=split(",",$word);
		$where1=$where2=array();
        $where1[]="services_goods_cate_id > 1";
        $where1[]="status=1";
        $where1[]="is_sell=1";
		foreach($word as $v){
			$where1[]= " services_goods_name like '%$v%'";
			$where2[]= " alias like '%$v%'";
		}
		$where1 = join(" and ",$where1);
		$where1 = "1 and ".$where1;
		$where2 = join(" and ",$where2);
		$where2 = "1 and ".$where2;
		$db=new model;
		
		//查找分类
		$cate=$db->model("aa_as_cate")->select("cate_id as id,cate_name as name")->where($where2)->limit(5)->getAll();
		$goods=$db->model("services_goods")->select("services_goods_id as id,services_goods_name as name")->where($where1)->limit(5)->getAll();
		$content=array_merge($cate,$goods);
		$result=array('error'=>0,'content'=>$content,'key'=>$word);
		$this->json_output($result);
	}
}


?>